import json
from flask import Blueprint,request,jsonify
from db import db
from utile.jwts import myjwt
from utile.comm import get_data
from utile.acl import acl
from utile.rs import r
bp_users = Blueprint('users',__name__)

@bp_users.route('/login',methods= ['POST'])
def login():
    data = get_data()
    username = data['username']
    password = data['password']
    # id = 1
    sql = 'select * from  users   where username="%s" and password="%s"'%(username,password)

    res = db.find(sql)
    data={'data':{'username':username,'uid':res['id']}}
    token =  myjwt.jwt_en(data) 
    
    # print(res)
    pagelist = acl.get_page_relist(res['id'])
    # print(pagelist)
    asdasdawdas = acl.get_interface_relist(res['id']) 

    return jsonify({'code':200,'uid':res['id'],'username':username,"token":token,'pagelist':pagelist,'asdasdawdas':asdasdawdas})


